package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.math.BigInteger;
import java.util.List;
import org.junit.Test;

/**
 * Demonstrates that the ListStringConverter is working.
 * 
 * @author Ed Kim
 * @author Jon Lao
 * @author Jianfei Liao
 * @author Jared Sunouchi
 */
public class TestListStringConverter {
  /** A converter for testing. */
  ListStringConverter converter = new ListStringConverter();
 
  /**
   * Test the String and list of String conversion.
   */
  @Test
  public void testStringAndList() {
    String string = "Hello World!, How you doing today?, I feel good.";
    
    // convert String to a list of String
    List<String> list = this.converter.stringToList(string);
    assertEquals("Testing the first element in list", "Hello World!", list.get(0));
    assertEquals("Testing the second element in list", "How you doing today?", list.get(1));
    assertEquals("Testing the third element in list", "I feel good.", list.get(2));
    
    // convert the list of String back to a String with commas
    list.add("Me too");
    String string2 = this.converter.listToString(list);
    assertEquals("Testing the String", 
        "Hello World!, How you doing today?, I feel good., Me too", string2);
    
    // tests with a null string
    try {
      string = null;
      this.converter.stringToList(string);
    }
    catch (Exception e) {
      assertNull("Testing special null case", string);
      e.getMessage();
    }
  }
  
  /**
   * Test the String and list of BigInteger conversion.
   */
  @Test
  public void testStringAndBigIntegerList() {
    String string = "2000, 2001, 2002";
    
    // convert the String to a list of BigInteger
    List<BigInteger> list = this.converter.stringToBigIntegerList(string);
    assertEquals("Testing the first element in list", "2000", list.get(0).toString());
    assertEquals("Testing the second element in list", "2001", list.get(1).toString());
    assertEquals("Testing the third element in list", "2002", list.get(2).toString());
    
    // convert the list of BigInteger back to a String with commas
    list.add(BigInteger.TEN);
    String string2 = this.converter.bigIntegerListToString(list);
    assertEquals("Testing the String", "2000, 2001, 2002, 10", string2);
    
    // tests with a null string
    try {
      string = null;
      this.converter.stringToBigIntegerList(string);
    }
    catch (Exception e) {
      assertNull("Testing special null case", string);
      e.getMessage();
    }
  }
}